/*
 * $Id: Sio.h,v 1.9 2006-02-07 04:17:55 bacon Exp $
 */

#ifndef XPP_BAS_SIO_CLASS_
#define XPP_BAS_SIO_CLASS_

#include <xpp/Uncopyable.h>
#include <xpp/bas/String.h>
#include <xp/bas/sio.h>

namespace xpp
{
	namespace bas
	{

		class Sio: public Uncopyable
		{
		public:
			Sio (): sio (XP_NULL) { } 
			Sio (xp_sio_t* sio): sio (sio) { }
			~Sio ();

			xp_fiohnd_t handle () const
			{
				xp_assert (this->sio != XP_NULL);
				return this->sio->fio.handle;
			}

			int open (const xp_char_t* path, const xp_char_t* mode);
			int opentmp (xp_char_t* tmpl, bool unlink_after_open = false);
			int close ();

			bool isOpen () const
			{
				return this->sio != XP_NULL;
			}

			xp_ssize_t gets (xp_char_t* buf, xp_size_t len)
			{
				xp_assert (this->sio != XP_NULL);
				return xp_sio_gets (this->sio, buf, len);
			}

			xp_ssize_t getsx (xp_char_t* buf, xp_size_t len)
			{
				xp_assert (this->sio != XP_NULL);
				return xp_sio_getsx (this->sio, buf, len);
			}

			xp_ssize_t puts (const xp_char_t* buf)
			{
				xp_assert (this->sio != XP_NULL);
				return xp_sio_puts (this->sio, buf);
			}

			xp_ssize_t putsx (const xp_char_t* buf, xp_size_t len)
			{
				xp_assert (this->sio != XP_NULL);
				return xp_sio_putsx (this->sio, buf, len);
			}

			xp_tri_t readLine (String* line);

		protected:
			xp_sio_t* sio;
		};

	}
}

#endif

